package o;

import android.app.usage.UsageStats;
import android.app.usage.UsageStatsManager;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import com.huawei.appgallery.appcomment.impl.bean.CommentDiagApplyResBean;
import com.huawei.appgallery.appcomment.impl.bean.CommentDiagApplyResBean.ReviewDialogApply;
import com.huawei.hmf.annotation.ApiDefine;
import java.util.Calendar;
import java.util.List;
import o.dys.a;

@ApiDefine(uri = bcj.class)
public class bcl implements bcj {
    private a ˋ;
    private bch ˎ;

    public void ˋ(bch o_bch, a aVar) {
        if (o_bch != null && aVar != null) {
            this.ˋ = aVar;
            this.ˎ = o_bch;
            cfw.ˎ(new bcx(o_bch.ˏ(), o_bch.ͺ()), new d(this, null));
        }
    }

    public void ˏ(String str, String str2) {
        if (!TextUtils.isEmpty(str2) && !TextUtils.isEmpty(str)) {
            cfw.ˎ(new bcv(str, str2), new d(this, null));
        }
    }

    private boolean ˏ(CommentDiagApplyResBean commentDiagApplyResBean) {
        if (this.ˎ == null || TextUtils.isEmpty(this.ˎ.ॱ())) {
            return false;
        }
        ReviewDialogApply ˏ = commentDiagApplyResBean.ˏ();
        if (ˏ == null || ˏ.ˎ() > ˏ.ˏ()) {
            return false;
        }
        int ॱ = ॱ(ˏ.ˊ());
        if (ॱ == -1 || ॱ < ˏ.ˋ()) {
            return false;
        }
        return true;
    }

    private int ॱ(int i) {
        UsageStatsManager usageStatsManager = (UsageStatsManager) ContentManager.getInstant().getContext().getSystemService("usagestats");
        Calendar instance = Calendar.getInstance();
        long timeInMillis = instance.getTimeInMillis();
        instance.add(5, i * -1);
        List<UsageStats> queryUsageStats = usageStatsManager.queryUsageStats(3, instance.getTimeInMillis(), timeInMillis);
        if (queryUsageStats == null || queryUsageStats.isEmpty()) {
            return -1;
        }
        if (this.ˎ != null) {
            for (UsageStats usageStats : queryUsageStats) {
                if (this.ˎ.ॱ().equals(usageStats.getPackageName())) {
                    try {
                        return usageStats.getClass().getDeclaredField("mLaunchCount").getInt(usageStats);
                    } catch (NoSuchFieldException e) {
                    } catch (IllegalArgumentException e2) {
                    } catch (IllegalAccessException e3) {
                    }
                }
            }
        }
        return -1;
        bcb.ˋ.ˊ("CommentDiaImpl", "getApplicationLauncherCount Exception");
    }

    private void ॱ(String str) {
        if (this.ˋ != null) {
            Intent intent = new Intent();
            Bundle ॱ = ber.ॱ(this.ˎ);
            ॱ.putString("DIALOG_NO", str);
            intent.putExtras(ॱ);
            intent.setClassName("com.huawei.appmarket", "com.huawei.appgallery.appcomment.ui.thirdcomment.ThirdDialogResultActivity");
            this.ˋ.startActivityForResult(intent, 1001);
        }
    }

    private void ˊ(int i) {
        if (this.ˋ != null) {
            this.ˋ.setResult(i);
            this.ˋ.finish();
        }
    }
}
